package core;

import core.utils.Variable;
import core.utils.VariableDataSet;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;

public class Model{
	private static Map<Variable, Integer> variableIds;
	private static List<Variable> variables = new ArrayList<Variable>();
	private TreeSet<VariableDataSet> data = new TreeSet<VariableDataSet>();
	private static Model instance = null;
	private static boolean connected = false;
	private final ArrayList<Variable> checkedVariables = new ArrayList<Variable>();
	
	//Singleton, prevent instantiation.
	private Model(){}
	
	public static Model getInstance(){
		if (instance == null){
			instance = new Model();
		}
		return instance;
	}
	
	public void initialize(Map<Variable, Integer> map, List<Variable> list){
		variableIds = map;
		variables = list;
	}

    public TreeSet<VariableDataSet> getData(){
		return data;
	}

    public void replaceData(TreeSet<VariableDataSet> data){
		this.data = data;
	}

    public List<Variable> getCheckedVariables(){
		return checkedVariables;
	}
	
	/**
	 * Returns map of variables and IDs. These IDs needs to correspond to the ones
	 * assigned to the variables in the database. Returns <code>null</code> unless
	 * <code>initialize</code> has been called.
	 */
	public static Map<Variable, Integer> getVariableIds() {
		return variableIds;
	}
	
	/**
	 * Returns a list of all available variables Returns <code>null</code> unless
	 * <code>initialize</code> has been called.
	 */
	public static List<Variable> getVariables(){
		return variables;
	}
	
	public boolean isConnected(){
		return connected;
	}
	
	public void setConnectionStatus(boolean newStatus){
		connected = newStatus;
	}
	
	public void addCheckedVariable(Variable var){
		checkedVariables.add(var);
	}

	public void removeCheckedVariable(Variable var) {
		checkedVariables.remove(var);
	}
}